package message

import (
	"time"

	"gorm.io/gorm"
)

// Message 消息实体
type Message struct {
	ID        uint           `gorm:"primarykey" json:"id"`
	TenantID  uint           `gorm:"index;not null" json:"tenant_id"`
	SenderID  uint           `gorm:"index;not null" json:"sender_id"`
	Title     string         `gorm:"size:100" json:"title"`
	Content   string         `gorm:"type:text" json:"content"`
	Type      int            `gorm:"default:1" json:"type"` // 1:系统消息 2:私信 3:公告
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

// TableName 表名
func (Message) TableName() string {
	return "message"
}

type MessageReceiver struct {
	ID         uint           `gorm:"primarykey" json:"id"`
	TenantID   uint           `gorm:"index;not null" json:"tenant_id"`
	MessageID  uint           `gorm:"index;not null" json:"message_id"`
	ReceiverID uint           `gorm:"index;not null" json:"receiver_id"`
	Status     int            `gorm:"default:1" json:"status"` // 1:未读 2:已读 3:删除
	ReadTime   *time.Time     `json:"read_time"`
	CreatedAt  time.Time      `json:"created_at"`
	UpdatedAt  time.Time      `json:"updated_at"`
	DeletedAt  gorm.DeletedAt `gorm:"index" json:"-"`
}

// TableName 表名
func (MessageReceiver) TableName() string {
	return "message_receiver"
}
